#include "wxshyperlinkctrl.h"
#include "wx/hyperlink.h"


namespace {
  wxsRegisterItem<wxsHyperlinkCtrl> Reg( _T( "HyperlinkCtrl" ), _T( "超链接" ), wxsTWidget, _T( "标准" ), 260 );
  WXS_ST_BEGIN( wxsHyperlinkCtrlStyles, _T( "wxHL_CONTEXTMENU|wxNO_BORDER|wxHL_ALIGN_CENTRE" ) )
  WXS_ST_CATEGORY( "wxHyperlinkCtrl" )
  WXS_ST( wxHL_CONTEXTMENU )
  WXS_ST( wxHL_ALIGN_LEFT )
  WXS_ST( wxHL_ALIGN_RIGHT )
  WXS_ST( wxHL_ALIGN_CENTRE )
  WXS_ST_DEFAULTS()
  WXS_ST_END()
  WXS_EV_BEGIN( wxsHyperlinkCtrlEvents )
  WXS_EVI( EVT_HYPERLINK, wxEVT_COMMAND_HYPERLINK, wxCommandEvent, Click )
  WXS_EV_END()
}

wxsHyperlinkCtrl::wxsHyperlinkCtrl( wxsItemResData* Data ):
  wxsWidget( Data, &Reg.Info, wxsHyperlinkCtrlEvents, wxsHyperlinkCtrlStyles ),
  m_Label( wxT( "http://www.test.org" ) ) {}

void wxsHyperlinkCtrl::OnBuildCreatingCode() {
  switch( GetLanguage() ) {
    case wxsCPP: {
      AddHeader( _T( "<wx/hyperlink.h>" ), GetInfo().ClassName, hfInPCH );
      Codef( _T( "%C(%W, %I, %t, %t, %P, %S, %T, %N);\n" ), m_Label.wx_str(), m_URL.wx_str() );
      wxString ss = m_NormalColour.BuildCode( GetCoderContext() );
      if( !ss.IsEmpty() ) {
        Codef( _T( "%ASetNormalColour(%s);\n" ), ss.wx_str() );
      }
      ss = m_HoverColour.BuildCode( GetCoderContext() );
      if( !ss.IsEmpty() ) {
        Codef( _T( "%ASetHoverColour(%s);\n" ), ss.wx_str() );
      }
      ss = m_VisitedColour.BuildCode( GetCoderContext() );
      if( !ss.IsEmpty() ) {
        Codef( _T( "%ASetVisitedColour(%s);\n" ), ss.wx_str() );
      }
      BuildSetupWindowCode();
      return;
    }
    case wxsUnknownLanguage:
    default: {
      wxsCodeMarks::Unknown( _T( "wxsHyperlinkCtrl::OnBuildCreatingCode" ), GetLanguage() );
    }
  }
}

wxObject* wxsHyperlinkCtrl::OnBuildPreview( wxWindow* parent, long flags ) {
  wxHyperlinkCtrl* preview = new wxHyperlinkCtrl( parent, GetId(), m_Label, m_URL, Pos( parent ), Size( parent ), Style() );
  wxColour cc = m_NormalColour.GetColour();
  if( cc.IsOk() ) {
    preview->SetNormalColour( cc );
  }
  cc = m_HoverColour.GetColour();
  if( cc.IsOk() ) {
    preview->SetHoverColour( cc );
  }
  cc = m_VisitedColour.GetColour();
  if( cc.IsOk() ) {
    preview->SetVisitedColour( cc );
  }
  return SetupWindow( preview, flags );
}

void wxsHyperlinkCtrl::OnEnumWidgetProperties( M_Code_unused long Flags ) {
  WXS_STRING( wxsHyperlinkCtrl, m_Label, _T( "Label" ), _T( "label" ), _T( "" ), false )
  WXS_SHORT_STRING( wxsHyperlinkCtrl, m_URL, _T( "URL" ), _T( "url" ), _T( "" ), false )
  WXS_COLOUR( wxsHyperlinkCtrl, m_NormalColour, _T( "Normal" ), _T( "normal_colour" ) )
  WXS_COLOUR( wxsHyperlinkCtrl, m_HoverColour, _T( "Hover" ), _T( "hover_colour" ) )
  WXS_COLOUR( wxsHyperlinkCtrl, m_VisitedColour, _T( "Visited" ), _T( "visited_colour" ) )
}
